package com.wen.controller.biz;


import com.wen.common.annotation.RepeatSubmit;
import com.wen.common.utils.ResponseResult;
import com.wen.system.service.LoginService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/open")
public class LoginController {

    @Autowired
    private LoginService loginService;

//加密密码：    SimpleHash simpleHash = new SimpleHash("MD5", user.getPassWord(), salt, 1024);

    /**
     * 点什么请求，就跳什么页面
     *
     * @return
     */
//    @RequestMapping("/{url}")
//    public String doUrl(@PathVariable("url") String url) {
//        return url;
//    }

    @RequestMapping("/main")
    public String main() {
        return "main";
    }
    @RequestMapping("/manage")
    public String manage() {
        return "manage";
    }
    @RequestMapping("/admin")
    public String admin() {
        return "admin";
    }
    @RequestMapping("/unAuthc")
    @ResponseBody
    public ResponseResult<?> unAuthc() {
        return ResponseResult.error("400","未授权！");
    }


    /**
     * 首页
     *
     * @return
     */
    @RequestMapping({"/", "/index"})
    public String doIndex() {
        return "index";
    }

    /**
     * 跳转登录页
     *
     * @return
     */
    @RequestMapping({"/login"})
    public String toLogin() {
        return "login";
    }

    /**
     * 退出
     * @return
     */
    @GetMapping("/loginOut")
    public String doLoginOut(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "index";
    }







    @RequestMapping("/test")
    @RepeatSubmit
    public String test(Model model) {
        model.addAttribute("msg", "<h1>hello springboot</h1>");
        return "test";
    }

    @RequestMapping("/testUser")
    @ResponseBody
    public String testUser() {
        return loginService.testUserService();
    }


    @GetMapping("/hello")
    @ResponseBody
    public ResponseResult<?> hello() {
        return ResponseResult.success("今晚的月色真美");
    }

    @RequestMapping("/error1")
    @ResponseBody
    public ResponseResult<?> error() {
//        return Result.error("-1","登录失败了");
        return ResponseResult.success();
    }


}
